package com.yunfeng.supercall.activity;

import java.util.Set;

import android.content.Intent;
import android.os.Bundle;
import android.preference.RingtonePreference;
import android.view.View;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;

import com.yunfeng.supercall.R;
import com.yunfeng.supercall.fragment.SettingFragment;
import com.yunfeng.supercall.service.CallConnectionService;

public class SettingActivity extends BaseActivity {
	SettingFragment fragment;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting);
		setTitleBar(R.string.setting);
		getSupportFragmentManager().beginTransaction()
				.replace(R.id.content, fragment = new SettingFragment())
				.commit();
	}

	public void switchAccount(View v) {
		// UCSService.uninit(this);
		stopService(new Intent(this, CallConnectionService.class));
		getLoginManager(getActivity()).logout();
		// System.exit(0);
		startActivity(new Intent(this, LoginActivity.class)
				.addFlags(
						Intent.FLAG_ACTIVITY_CLEAR_TASK
								| Intent.FLAG_ACTIVITY_NEW_TASK).putExtra(
						"autologin", false));
		JPushInterface.setAlias(getApplicationContext(), "",
				new TagAliasCallback() {

					@Override
					public void gotResult(int arg0, String arg1,
							Set<String> arg2) {
					}
				});
		JPushInterface.stopPush(getApplicationContext());
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		// 给设置Fragment传递onActivityResult事件
		RingtonePreference preference = (RingtonePreference) fragment
				.findPreference("music");
		preference.onActivityResult(requestCode, resultCode, data);
	}
}
